<template>
	<view>
		<!-- <unicloud-db ref="userRef" v-slot:default="{data, loading, error, options}" collection="uni-id-users"
			:where="where" :field="field" getcount @load="loadData" orderby="invite_time desc">
			<view v-if="error">{{error.message}}</view>
			<view v-else> -->
				<uni-list>
					<uni-list-item v-for="item in dataList" :key="item?.uid">
						<template v-slot:body>
							<view
								style="display: flex;align-items: center;justify-content: space-between;width: 100%;font-size: 13px;" @click="navigator(item?.uid)">
								<image :src="item?.avatar_file?.url || logo" mode="aspectFill"
									style="width: 100rpx;height: 100rpx;border-radius: 5px;"></image>
								<view style="display: flex;flex-direction: column;margin-left: 5px;flex: 1;">
									<text>{{item?.nickname}}</text>
									<text>{{item?.mobile}}</text>
									<text v-if="item.gender">{{localgender[item.gender]}}</text>
								</view>
								<uni-dateformat :date="item.inviteTime" />
							</view>
						</template>
					</uni-list-item>
					<uni-load-more :status="more" @clickLoadMore="clickLoadMore" :content-text="contentText"></uni-load-more>
				</uni-list>
			<!-- </view>
		</unicloud-db> -->
	</view>
</template>

<script>
	import {
		mapState
	} from "pinia"
	import {
		useUserStore
	} from "@/pinia/user.js"
	import logo from "@/static/logo.png"
	const USERS = uniCloud.importObject('uni-id-co')
	
	export default {
		data() {
			return {
				dataList:[],
				localgender:['','男','女'],
				logo,
				field: "nickname,avatar_file,mobile,invite_time,gender",
				more: "more",
				contentText: {
					contentdown: '点击加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				offset:0,
			}
		},
		computed: {
			...mapState(useUserStore, ['userInfo']),
			// where() {
			// 	return `inviter_uid.0 == $env.uid`
			// }
		},
		mounted() {
			this.loadData()
		},
		methods: {
			async loadData() {
				let res = await USERS.getInvitedUser({
					needTotal: true,
					level:1,
					offset:this.offset,
				})
				console.log("res========>",res);
				this.dataList = [...this.dataList,...res.invitedUser]
				this.offset += 20
				if(res.total >= this.offset){
					this.more = "more"
				}else{
					this.more = "no-more"
				}
				
			},
			clickLoadMore(e){
				if(e.detail.status=="more"){
					this.loadData()
				}
				// console.log("e===================+++++++++",e.detail);
			},
			navigator(id){
				console.log("id===>>>",id);
				if(!id) return
				uni.navigateTo({
					url:`/pages/list/userInfo?id=${id}`
				})
			}
		}
	}
</script>

<style>

</style>